package com.sinopec.basemodule.api

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.sinopec.basemodule.http.HttpParamObj
import com.sinopec.basemodule.http.api.HttpResult
import com.sinopec.basemodule.http.api.RetroAPIFactory
import com.sinopec.basemodule.model.ProductSpecModel
import io.reactivex.Observable

/**
 * @author lwj
 * @ClassName: BaseModuleService
 * @Description: 公有接口
 */
object BaseModuleApi {

    private val iService: BaseModuleService by lazy {
        RetroAPIFactory.create(BaseModuleService::class.java)
    }
    private val gson: Gson by lazy { Gson() }
    private val parseType = object : TypeToken<HashMap<String, Any?>>() {}.type

    /**
     * 退出登录
     */
    fun loginOut(): Observable<HttpResult<Any?>?>? {
        val end = HttpParamObj.createParams()
            .end()
        return iService.loginOut(end)
    }

    /**
     * 按单-预分拣弹窗下拉规格
     */
    fun getSortOrderProductSpecListBySortOrder(productCategoryId: String, productBusinessId: String): Observable<HttpResult<List<ProductSpecModel?>>> {
        val hashMap = HttpParamObj.createParams()
            .putParam("productCategoryId", productCategoryId)//大类id
            .putParam("productBusinessId", productBusinessId)//业务类型id
            .end()
        return iService.getSortOrderProductSpecListBySortOrder(hashMap)
    }

    /**
     * 预分拣弹窗下拉规格
     */
    fun getProductSpecList(productCategoryId: String, productBusinessId: String): Observable<HttpResult<List<ProductSpecModel?>>> {
        val hashMap = HttpParamObj.createParams()
            .putParam("productCategoryId", productCategoryId)//大类id
            .putParam("productBusinessId", productBusinessId)//业务类型id
            .end()
        return iService.getProductSpecList(hashMap)
    }
}